<template>
  <div class="container" >
    <h2>用户登录</h2>

      <div class="form-group">
        <label for="email">Email:</label>
        <input type="email" class="form-control" id="email" placeholder="Enter email" name="email" v-model="user">
      </div>
      <div class="form-group">
        <label for="pwd">Password:</label>
        <input type="password" class="form-control" id="pwd" placeholder="Enter password" name="password" v-model="password">
      </div>
      <div class="form-check">
        <label class="form-check-label">
          <input class="form-check-input" type="checkbox"> Remember me
        </label>
      </div>
      <button type="submit" class="btn btn-primary" @click="login">Submit</button>

  </div>
</template>

<script>
    export default {
        name: "Index",
        data(){
          return {
            user:'',
            password:''
          }
        },
        methods:{
            login:function() {
              let that = this;
              let isBtnLoading = false;
              let user = this.user;
              let password = this.password;
              console.log("m12");
              console.log(user);
              console.log(password);
              let data = new FormData();
              data.append('user',user);
              data.append('password',password);
              this.axios.post('/login',data)
              .then(function (response){
                console.log(response);
                if (response.status === 200){
                    isBtnLoading = response.data.isBtnLoading;
                    console.log(isBtnLoading);
                    if(isBtnLoading === true){
                      console.log("判断正确！");
                      that.$router.push({path:'/hello'});
                      console.log("确认跳转！");
                    }
                  }else{
                    alert("工厂倒闭了，你离远点~")
                  }
              })
                .catch(function (error) {
                  alert("你干什么？？？");
                  console.log(error);
                });
          }
      },
    }
</script>

<style scoped>

</style>
